package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallUserErMapper;
import org.linlinjava.litemall.db.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallUserErService {

    @Resource
    private LitemallUserErMapper userErMapper;


    /*userEr登录
     */
    public List<LitemallUserEr> queryByUsernameEr(String username) {
        LitemallUserErExample erExample = new LitemallUserErExample();
        erExample.or().andUsernameEqualTo(username);
        return userErMapper.selectByExample(erExample);
    }

    public Object queryAllUser() {
        LitemallUserErExample erExample = new LitemallUserErExample();
        return userErMapper.selectByExample(erExample);
    }

    public Object create(LitemallUserEr litemallUserEr) {
        int i = userErMapper.insert(litemallUserEr);
        return i;
    }

    //批量增加
    public int createUsers(List<LitemallUserEr> userErList) {
       return userErMapper.insertUsers(userErList);
    }

    public LitemallUserEr queryAllById(String username) {
        return userErMapper.queryAllById(username);
    }

    public void updateUserDeleteId(int id){
        userErMapper.updateUserDeleteId(id);
    }
    @Transactional(rollbackFor = Exception.class)
    public int updateUserErById(String username, String balance) {
        return userErMapper.updateUserEr(username, balance);
    }

    // 通过id返回账户名 密码
    public LitemallUserEr selectUsernamePwd(int id){
        return userErMapper.selectUsernamePwd(id);
    }

}